from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.common.by import By


# 初始化浏览器对象
driver = webdriver.Chrome(ChromeDriverManager().install())
# 最大化浏览器
driver.maximize_window()
# 打开百度页面
driver.get('https://www.baidu.com')
time.sleep(2)

# # 搜索坚果
# # 1、找到输入框元素
# # input_element = driver.find_element_by_xpath("//input[@id='kw']")
# input_element = driver.find_element(By.XPATH, "//input[@id='kw']")
# # 2、输入值-坚果
# input_element.send_keys("坚果")
# time.sleep(2)
# input_element.clear()
# time.sleep(2)
# input_element.send_keys("python")
# time.sleep(2)
# # 找到【百度一下】按钮元素
# # baidu_button = driver.find_element_by_css_selector("input[id=su]")
# baidu_button = driver.find_element(By.CSS_SELECTOR, "input[id=su]")
# # 点击-百度一下这个元素
# baidu_button.click()
# time.sleep(2)

# # 找到表单submit
# driver.find_element(By.CSS_SELECTOR, "form").submit()

# # 定位一组元素
# elements = driver.find_elements(By.CSS_SELECTOR, "a[class^=title-content]")
# for i in elements:
#     # 点击单个元素
#     i.click()
#     time.sleep(2)
# time.sleep(2)

# 定位到设置按钮
set_element = driver.find_element(By.XPATH, "//span[@name='tj_settingicon']")
# # 获取文本内容
# print(set_element.text)
# # 获取元素属性值
# print(set_element.get_attribute('class'))
# print(set_element.get_attribute('id'))
# print(set_element.get_attribute('name'))
# print(set_element.get_attribute('value'))  # 获取不到返回None
# # 获取元素尺寸
# print(set_element.size)
print(set_element.is_displayed())


time.sleep(5)

driver.quit()